<?php

namespace App\Console\Commands;

use App\Models\StudentApplication;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class Demo extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'demo:run';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    // 报名矫正程序
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $a = StudentApplication::query()->groupBy(['club_id','class_and_grade_id','time_id','school_id'])->get();
        $t = 0;
        foreach ($a as $v){
            $count = StudentApplication::query()->where([
                'club_id'=>$v->club_id,
                'class_and_grade_id'=>$v->class_and_grade_id,
                'time_id'=>$v->time_id,
                'school_id'=>$v->school_id,
            ])->count('id');
            $t += $count;
            $countKey = sprintf('%s_%s_%s_%s',$v->club_id, $v->school_id, $v->class_and_grade_id, $v->time_id);
            Redis::set($countKey,$count);
        }

        dd($t);
    }
}
